﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace BDSim
{
    public class NoiseServiceDLL
    {
        /// <summary>
        /// 随机误差计算函数
        /// </summary>
        /// <param name="pCalRan_Input">包含噪声量级DeltRanThH和随机噪声结构体pRandomNoise</param>
        /// <param name="Iran">模型开关标志，0表示不考虑，1表示白噪声</param>
        /// <returns></returns>
        [DllImport("NoiseServiceDLL.dll", EntryPoint = "CalRan_output", CallingConvention = CallingConvention.Cdecl)]
        public static extern double CalRan_output(ref CalRan_Input pCalRan_Input, int Iran);

        /// <summary>
        /// 随机误差计算函数，C#建议调用此函数
        /// </summary>
        /// <param name="DeltRanThH">随机误差量级</param>
        /// <param name="Iran">模型开关标志，0表示不考虑，1表示白噪声</param>
        /// <returns></returns>
        public static double CalRan_Input(double DeltRanThH, int Iran)
        {
            Random ran = new Random();
            CalRan_Input pCalRan_Input;
            RandomNoise Noise = new RandomNoise();
            Noise.ran1_iv = new double[32];
            Noise.idum = ran.Next(-100, 100);
            Noise.PR_idum = 500;
            pCalRan_Input.pRandomNoise = Noise;
            pCalRan_Input.DeltRanThH = DeltRanThH;
            double ranerr;
            ranerr = NoiseServiceDLL.CalRan_output(ref pCalRan_Input, 1);
            return ranerr;

        }
            

    }
}
